'use strict';
	angular.module('invoice.payableCGFPSingle', [])

	.controller('payableCGFPSingleCtrl'
			,['$rootScope', '$scope','systemService', 'uServiceCenter' ,'BizData', 'apiService'
			   , f])//控制器结束
	function f($rootScope,$scope, systemService, uServiceCenter, BizData, apiService
					   ) {
		var common = require('common');
		
		var Model = this;
//		$scope.path = $rootScope.path;
//		$scope.createPermission = $rootScope.path + ':create';
		
		//定义页面级别的变量
		var systemCode = $rootScope.winid; //系统代码

		var flowType = 0;
		var billTypeName = "";
		var originName = "";

		var autoCode; //是否自动编码
		var revOpay; //入库出库
		var costingCode; //影响成本码
		
		var storageType ;
		var storageTypeLabel ;
		var storageNo;
		var storageName;
		var floorNo;

		/////////////////////////////////////////////////////////////////////////////////////////////////

		var billType = 'CGFP';
		var direction;
//		var departmentNo;
//		var departmentName;
		var employeeNo;
		var employeeName;

		var accountInvoiceNo;
		var maxDetailNo;
		var serialNo;

		var origin;

		var factoryID;
		var factoryNo;
		var factoryName;
		
		var billNo;

		var state;
		var status;
		var audit;
		var orderDate;
		
		var userId;
		var enterpriseNo;
		var enterpriseName;
		
		var taxType;
		var taxTypeLabel;
		var taxRate;
		
		var dealObject = 'pro';
		var dealObjectLabel = '供应商';
		var customerID;
		var customerNo;
		var shortName
		var customerName;

//		var clearType='1';
//		var clearTypeLabel='1.采购发票';
//		var writeOffNo;
		
		var isMember;
		var memberNo;
		
		/**
		name:bizData#onNewCreateParam
		description: <b>[回调型事件]</b>业务新增数据创建新增参数事件，可以增加和修改用户自定义的参数
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"param" : {justep.Request.ActionParam} 新增参数对象,
			"defaultValues" : array - 新增行的默认值数组 ，数组的长度决定新增行数，数组中的对象是列的默认值
				defaultValues格式：
					[
						{列名:默认值,...},
						{列名:默认值,...},
						...
					]
		}
		</xmp>	
		@see justep.XData#newData
		@see justep.Request.ActionParam
		*/
		Model.dataMasterNewCreateParam = function(event) {
			event.param = {"billType": billType};
		}
		
		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataMasterBeforeNew = function(event) {

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataMasterAfterNew = function(event){
			//创建行后赋值
			event.source.setValue('systemCode',systemCode,event.id);
			
			event.source.setValue('dealObject',dealObject, event.id);
			event.source.setValue('dealObjectLabel',dealObjectLabel, event.id);

//			event.source.setValue('clearType', clearType, event.id);	
//			event.source.setValue('clearTypeLabel', clearTypeLabel, event.id);	
			
			event.source.setValue('handling', 'unclear', event.id);
			event.source.setValue('handlingLabel', '待核销', event.id);

			//产生自动流水号
			//获取初始化参数
			//获取单据参数
			var enterpriseNo = event.source.getValue("enterpriseNo", event.id);
			if(billType && enterpriseNo){
				var options = {};
				options.billType = billType;
				options.ognID = enterpriseNo;
				options.async = false;
				var billParam = systemService.getBillParam(options);
				if (billParam.state == "success"){
					event.source.setValue('dealType',billParam.dealType,event.id);
					event.source.setValue('billTypeName',billParam.billTypeName,event.id);
					event.source.setValue('flowType',billParam.flowType,event.id);
					event.source.setValue('origin', billParam.origin, event.id);	
					event.source.setValue('originName', billParam.originName, event.id);	
					event.source.setValue('revOpay', billParam.revOpay, event.id);	
					event.source.setValue('direction', billParam.direction, event.id);
					//event.source.setValue('costingCode', billParam.costingCode, event.id);	
					
					if (billParam.autoCode = "Y"){
						//产生自动流水号
						event.source.setValue('accountInvoiceNo',billParam.billNo,event.id);
					}
				}else{
					systemService.dialogMsg('请在单据设置中进行初始化。');
				}
			}
			
		}

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataMasterBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataMasterAfterDelete = function(event) {
//			alert('删除之后！')
		}

		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataMasterIndexChanged = function(event) {
			if(event.rowID!=null){
				Model.dataDetail.fMasterID = event.rowID;
	       		Model.dataDetail.refreshData();
			}else{
				Model.dataDetail.clearData();
			}
		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataMasterDataChanged = function(event) {
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataMasterValueChanged = function(event) {
			uServiceCenter.invoiceMasterValueChanged(event);
		}
		
		
		Model.dataMasterBeforeSave = function(event) {
//			console.log('dataMasterBeforeSave-->',event);

		};
		
		
		Model.dataMasterAfterSave = function(event) {
			//保存子表
//			Model.dataDetail.saveData();
			
		}
		

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataDetailBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
//			event.cancel = true;
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataDetailAfterDelete = function(event) {
			uServiceCenter.invoiceDetailAfterDelete(event);
		}
		
		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataDetailIndexChanged = function(event) {

		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataDetailDataChanged = function(event) {
			
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataDetailValueChanged = function(event) {
			uServiceCenter.invoiceCalculate(event);
		}
		

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataDetailBeforeNew = function(event) {
			// 明细数据新增之前
			// 检查主表中的数据是否完整
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			
			state = dataMaster.getValue('state', rowID);
			status = dataMaster.getValue('status', rowID);
			audit = dataMaster.getValue('audit', rowID);
			orderDate = dataMaster.getValue('orderDate', rowID);
			
			//////////////////////////////////////////////////////////////////////
			systemCode = dataMaster.getValue('systemCode', rowID);
			//////////////////////////////////////////////////////////////////////

			// 判断如果那些为空，则拒绝新增明细数据
			customerID = dataMaster.getValue('customerID', rowID);
			customerNo = dataMaster.getValue('customerNo', rowID);
			shortName = dataMaster.getValue('shortName', rowID);
			customerName = dataMaster.getValue('customerName', rowID);
			
			isMember = dataMaster.getValue('isMember', rowID);
			memberNo = dataMaster.getValue('memberNo', rowID);
			
			if (customerNo == null || customerNo == "") {
				// 取消新增操作
//				alert('出入库部门不能为空！请先选择主表中的出入库部门，然后再在明细表中新增行。')
				event.cancel = true;
				systemService.dialogMsg('交易对象不能为空！请先选择主表中的交易对象，然后再在明细表中新增行。');
			}

			billType = dataMaster.getValue('billType', rowID);
			direction = dataMaster.getValue('direction', rowID);
//			departmentNo = dataMaster.getValue('departmentNo', rowID);
//			departmentName = dataMaster.getValue('departmentName', rowID);
			employeeNo = dataMaster.getValue('employeeNo', rowID);
			employeeName = dataMaster.getValue('employeeName', rowID);
			dealObject = dataMaster.getValue('dealObject', rowID);
			dealObjectLabel = dataMaster.getValue('dealObjectLabel', rowID);

			accountInvoiceNo = dataMaster.getValue('accountInvoiceNo', rowID);
			
			//处理从表流水号
			maxDetailNo=dataMaster.getValue('maxDetailNo', rowID);
			maxDetailNo++;
			var detailNo=common.preZeroFill(maxDetailNo, 5);
			serialNo=detailNo;
				
			billTypeName = dataMaster.getValue('billTypeName', rowID);
			
			//////////////////////////////////////////////////////////////////////
			revOpay = dataMaster.getValue('revOpay', rowID);
			//////////////////////////////////////////////////////////////////////
			
			taxType = dataMaster.getValue('taxType', rowID);
			taxTypeLabel = dataMaster.getValue('taxTypeLabel', rowID);
			taxRate = dataMaster.getValue('taxRate', rowID);
			
			userId = dataMaster.getValue('userId', rowID);
			enterpriseNo = dataMaster.getValue('enterpriseNo', rowID);
			enterpriseName = dataMaster.getValue('enterpriseName', rowID);

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataDetailAfterNew = function(event){
			var dataDetail = event.source;
			var rowID = event.id;

			dataDetail.setValue('state', state, rowID);
			dataDetail.setValue('status', status, rowID);
			dataDetail.setValue('audit', audit, rowID);
			dataDetail.setValue('orderDate', orderDate, rowID);

			dataDetail.setValue('billType', billType, rowID);
			dataDetail.setValue('direction', direction, rowID);
//			dataDetail.setValue('departmentNo', departmentNo, rowID);
//			dataDetail.setValue('departmentName', departmentName, rowID);
			dataDetail.setValue('employeeNo', employeeNo, rowID);
			dataDetail.setValue('employeeName', employeeName, rowID);
			dataDetail.setValue('dealObject', dealObject, rowID);
			dataDetail.setValue('dealObjectLabel', dealObjectLabel, rowID);	

			dataDetail.setValue('customerID', customerID, rowID);
			dataDetail.setValue('customerNo', customerNo, rowID);
			dataDetail.setValue('shortName', shortName, rowID);
			dataDetail.setValue('customerName', customerName, rowID);
			
			dataDetail.setValue('isMember', isMember, rowID);
			dataDetail.setValue('memberNo', memberNo, rowID);

			dataDetail.setValue('accountInvoiceNo', accountInvoiceNo, rowID);	

			dataDetail.setValue('serialNo', serialNo, rowID);

			////////////////////////////////////////////////////////////////////////////////////
			dataDetail.setValue('systemCode', systemCode, rowID);
			/////////////////////////////////////////////////////////////////////////////////////////
			

			dataDetail.setValue('billTypeName', billTypeName, rowID);
			
			////////////////////////////////////////////////////////////////////////////////////
			dataDetail.setValue('revOpay', revOpay, rowID);
			/////////////////////////////////////////////////////////////////////////////////////////
			
			//更新主表计数器（从表最大流水号）
			var dataMaster = Model.dataMaster;
			var masterRowID = dataMaster.getCurrentID();
			dataMaster.setValue('maxDetailNo', maxDetailNo, masterRowID);	
			
			//更新主表中子表记录数
			dataMaster.setValue('detailsCount', dataMaster.getValue('detailsCount', masterRowID) + 1, masterRowID);	

			dataDetail.setValue('taxType', taxType, rowID);
			dataDetail.setValue('taxTypeLabel', taxTypeLabel, rowID);
			dataDetail.setValue('taxRate', taxRate, rowID);

			dataDetail.setValue('userId', userId, rowID);
			dataDetail.setValue('enterpriseNo', enterpriseNo, rowID);
			dataDetail.setValue('enterpriseName', enterpriseName, rowID);

			dataDetail.setValue('fMasterID',dataDetail.fMasterID,rowID);

		}
		
		///////////////////按钮组开始///////////////////////////////////////////////////
		//新建
		Model.add = function(){
			
		     var options = {
			         index : 0,
			         defaultValues : [
			             {
			            	 state:'active'
			            	 ,status:'open'
			            	 ,audit:'active'
			            	 ,taxType:1
			            	 ,taxTypeLabel:'1.应税内含'
			            	 ,taxRate:0
			            	 
			            	 ,exchangeRate:0
			            	 ,entryFlag:0
			            	 ,depositRate:0
			            	 ,cashSettle:0
			            	 ,retailFlag:0
			            	 ,pendingAmount:0
			            	 ,accountPendingAmount:0
			            	 
			            	 ,itemAmount:0
			            	 ,orderAmount:0
			            	 ,orderAmountOld:0
			            	 ,orderAmountTax:0
			            	 ,orderAmountTotal:0
			            	 
			            	 ,discountCash:0
			            	 ,discountRate:1
			            	 
			            	 ,accountAmountOld:0
			            	 ,accountAmountTax:0
			            	 ,accountAmountTotal:0
//			            	 ,accountAmountActualI:0
//			            	 ,accountAmountActualO:0
			            	 ,orderAmountCleared:0
			            	 ,orderAmountCleareding:0
//			            	 ,iptClearedAmount:0
//			            	 ,iptCashDiscount:0
			            	 ,accountAmountCleared:0
			            	 
			            	 ,freightAmount:0
			            	 ,apportionAmount:0
			            	 ,billAmount:0
			            	 ,totalAmount:0
			            	 ,accountTotalAmount:0
			            	 
			            	 ,receiveCashAmount:0
			            	 ,giveChangeAmount:0
			            	 ,discountCash:0//现金折扣
			            	 ,discountAmount:0
			            	 
			            	 ,resultStatus:'待审核'
			            	 ,paymentStatus:'待付款'
			            		
			            	 ,detailsCount:0
			            	 ,detailsCountState:0
			            	 ,maxDetailNo:0
			            	 
			            	 ,billType: billType
			            	 ,orderDate: ':getCurrentDate()'
				             ,employeeNo: ':getCurrentPsmFID()'
					         ,employeeName: ':getCurrentPsmFName()'
				             ,cUsercode: ':getCurrentPersonCode()'
					         ,cUsername: ':getCurrentPersonName()'
						     ,cDatetime: ':getCurrentDateTime()'
							 ,userId: ':getCurrentPersonID()'
							 ,enterpriseNo: ':getCurrentOgnFID()'
							 ,enterpriseName: ':getCurrentOgnLongName()'
							 ,version: 0

			            }//,
//			             {itemNo:'a2',itemDescribe:'b2'}
			         ]
			     };    

			Model.dataMaster.newData(options);

			if($scope.tabpanel!='single'){
				$scope.tabpanel='single'
			}
		}
		//修改
		Model.edit = function(){
			Model.dataMaster.editData();
			if($scope.tabpanel!='single'){
				$scope.tabpanel='single'
			}
		}
		
		//保存
		Model.save = function() {
			Model.dataMaster.saveData();
		}

		//取消编辑
		Model.saveCancel = function() {
			Model.dataMaster.editCancel();
		}
		
		/*
		//不提示直接提交后台删除当前行
		var data = justp.xbl('mainData');
		var deleteConfirm = data.deleteConfirm;
		var directDeleteMode = data.directDeleteMode;
		try{
		    data.deleteConfirm = false;
		    data.directDeleteMode = true;
		    data.deleteData(data.getID());
		}finally{
		    data.deleteConfirm = deleteConfirm;
		    data.directDeleteMode = directDeleteMode;
		}
		*/
		Model.remove = function() {
			Model.dataMaster.deleteData(Model.dataMaster.getCurrentID());
			Model.dataMaster.refreshData();
		};
		
		//刷新
		Model.refresh = function() {
			Model.dataMaster.refreshData();
		}
		
		
		//输出：在浏览器窗口打开/下载打印（打印和导出）
		Model.printExport = function() {
			var options = {};
			options.path = $rootScope.getServiceName() + $rootScope.path + "/printPDF";
			options.id = Model.dataMaster.getCurrentID();
			if($rootScope.separation==0){
				//整体项目
				systemService.openPrintExportWindow(options); 
			}else{
				//前后端分离
				systemService.downloadExport(options); 
			}
		};

		///////////////////按钮组结束///////////////////////////////////////////////////
		///////////////////子表按钮组开始///////////////////////////////////////////////////
		//增加
		Model.addrow = function(){
		     var options = {
			         index : Model.dataDetail.getCount(),
			         defaultValues : [
			             {
			            	 itemPrice:0.00
			            	 ,discountRate:1
			            	 ,itemAmount:0
			            	 ,orderAmount:0
			            	 ,orderAmountOld:0
			            	 ,orderAmountTax:0
			            	 ,orderAmountTotal:0
			            	 ,dealPrice:0
			            	 ,evaluateQuantityRinse:0
			            	 ,evaluateAmountRinse:0
			            	 ,discountAmount:0
			            	 
			            	 ,lv:0
			            	 ,sttts:0
			            	 ,checkin:0
			            	 ,costingAmount:0
			            	 ,costingAmountPer:0
			            	 
			            	 ,resultStatus:'待审核'
			            }//,
//			             {itemNo:'a2',itemDescribe:'b2'}
			         ]
			     };    

			Model.dataDetail.newData(options);
		}
		Model.delrow = function() {
			 if(Model.dataDetail.directDeleteMode){
				//直接删除
				 if(Model.dataDetail.deleteData(Model.dataDetail.getCurrentID())==0){
//					 Model.dataDetail.refreshData();
				 }
			 }else{
				//前台移除
				 if(Model.dataDetail.removeData(Model.dataDetail.getCurrentID())==0){
//					 Model.dataDetail.recordState = 'delete';
				 }
			 }
		};
		///////////////////子表按钮组结束///////////////////////////////////////////////////

		
		
		//打开对话框（选择供应商）
		Model.triggerProviderNoClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		var customerNo = dataMaster.getValue('customerNo', rowID);
     		if(customerNo!=null && customerNo!=''){
//         		dataMaster.setValue('dealObject', null, rowID);
//         		dataMaster.setValue('dealObjectLabel', null, rowID);
         		dataMaster.setValue('customerID', null, rowID);
         		dataMaster.setValue('customerNo', null, rowID);
         		dataMaster.setValue('shortName', null, rowID);
         		dataMaster.setValue('customerName', null, rowID);
     			return;
     		}

			var options = {};
			
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

			var modalInstance = systemService.openProviderNoDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
//	             		alert(returnData[i].sID+'-->'+returnData[i].sFName);
//	             		dataMaster.setValue('dealObject', returnData[i].storageTypeD, rowID);
//	             		dataMaster.setValue('dealObjectLabel', returnData[i].storageTypeDLabel, rowID);
	             		dataMaster.setValue('customerID', returnData[i].fID, rowID);
	             		dataMaster.setValue('customerNo', returnData[i].providerNo, rowID);
	             		dataMaster.setValue('shortName', returnData[i].shortName, rowID);
	             		dataMaster.setValue('customerName', returnData[i].providerName, rowID);
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
		}
		

		//打开对话框（选择经办人）
		Model.triggerEmployeeNoClick = function(){
			
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		var employeeNo = dataMaster.getValue('employeeNo', rowID);
     		if(employeeNo!=null && employeeNo!=''){
         		dataMaster.setValue('employeeNo', null, rowID);
         		dataMaster.setValue('employeeName', null, rowID);
     			return;
     		}
			
			
			var options = {};
			options.id = dataMaster.getValue('enterpriseNo',rowID);
			//是否显示人员
			options.psm = true;

			var modalInstance = apiService.openOrgNoDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
//	             		alert(returnData[i].sID+'-->'+returnData[i].sFName);
	             		dataMaster.setValue('employeeNo', returnData[i].sFID, rowID);
	             		dataMaster.setValue('employeeName', returnData[i].sFName, rowID);
	         			
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		}


		//打开对话框（选择物料）
		Model.grid_itemNoButtonClick = function(){
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);

			var modalInstance = systemService.openItemNoDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var simpleRow = event.data[0];
	        	systemService.itemSelectSingle(simpleRow,Model.dataDetail);

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		}
		
		//打开多选对话框（选择物料）
		Model.addrows = function(){
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			var options = {};
			options.recordState = 'none';
			options.id = dataMaster.getValue('enterpriseNo',rowID);
			var modalInstance = systemService.openItemNosDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
				var returnData = event.data;
		    	for ( var i = 0; i < returnData.length; i++) {
		    		//新增行
		    		Model.addrow();
		    		var simpleRow = returnData[i];
		        	systemService.itemSelectSingle(simpleRow,Model.dataDetail);
		    	}
	        	
	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		}
		
		//打开多选对话框（选择采购/委外进货）
		Model.addrowsByOrder = function(){
     		var dataMaster = Model.dataMaster;
     		var rowID = dataMaster.getCurrentID();
     		var customerID = dataMaster.getValue('customerID', rowID);
     		//截取供应商ID
     		if(customerID!=undefined && customerID!=''){
//     			customerID = customerID.substring(0,customerID.indexOf('/'));
     			customerID = customerID.substring(customerID.indexOf('/')+1,customerID.length);
     			console.log('customerID-->',customerID);
     		}else{
     			alert('请先选择供方！');
     			return;
     		}

     		var options = {};
			
			options.recordState = 'none';
			options.id = customerID;
			options.id = dataMaster.getValue('enterpriseNo',rowID);
     		var direction = dataMaster.getValue('direction', rowID);
     		if(direction==1){
    			options.filter = "StorageRecordDetail.providerID like '%"+customerID+"%'"
    			+ " AND (StorageRecordDetail.billType='CGRK' OR StorageRecordDetail.billType='WWRK')"
    			;
     		}
     		if(direction==-1){
    			options.filter = "StorageRecordDetail.providerID like '%"+customerID+"%'"
    			+ " AND (StorageRecordDetail.billType='CGCK' OR StorageRecordDetail.billType='WWCK')"
    			;
     		}
     		
			var modalInstance = systemService.openRecordDetailInvoiceDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	        	var dataDetail = Model.dataDetail;
				var returnData = event.data;
		    	for ( var i = 0; i < returnData.length; i++) {
		    		//新增行
		    		Model.addrow();
		    		var simpleRow = returnData[i];
		    		console.log('simpleRow-->',simpleRow);
		    		
		    		var rowID = dataDetail.getCurrentID();

					dataDetail.setValue('origin', simpleRow.billType, rowID);
					dataDetail.setValue('originName', simpleRow.billTypeName, rowID);
					dataDetail.setValue('originNo', simpleRow.recordNo, rowID);
					dataDetail.setValue('originSerialNo', simpleRow.serialNo, rowID);
					
	     			dataDetail.setValue('itemID', simpleRow.itemID, rowID);
					dataDetail.setValue('itemNo', simpleRow.itemNo, rowID);
					dataDetail.setValue('itemDescribe', simpleRow.itemDescribe, rowID);
					dataDetail.setValue('itemName', simpleRow.itemName, rowID);
					dataDetail.setValue('itemProperty', simpleRow.itemProperty, rowID);
					dataDetail.setValue('unitCode', simpleRow.unitCode, rowID);
					dataDetail.setValue('unitName', simpleRow.unitName, rowID);
//					dataDetail.setValue('process', simpleRow.process, rowID);
//					dataDetail.setValue('processLabel', simpleRow.processLabel, rowID);
//					dataDetail.setValue('costingType', simpleRow.costingType, rowID);
//					dataDetail.setValue('qualityType', simpleRow.qualityType, rowID);
//					dataDetail.setValue('qualityTypeLabel', simpleRow.qualityTypeLabel, rowID);
//					dataDetail.setValue('qualityPeriod', simpleRow.qualityPeriod, rowID);
//					dataDetail.setValue('validDays', simpleRow.validDays, rowID);
//					dataDetail.setValue('checkoutAgainDays', simpleRow.checkoutAgainDays, rowID);
					
//					dataDetail.setValue('storeNo', simpleRow.storeNo, rowID);
//					dataDetail.setValue('batchNo', simpleRow.batchNo, rowID);

         			dataDetail.setValue('storageType', simpleRow.storageType, rowID);
         			dataDetail.setValue('storageTypeLabel', simpleRow.storageTypeLabel, rowID);
         			dataDetail.setValue('storageID', simpleRow.storageID, rowID);
         			dataDetail.setValue('storageNo', simpleRow.storageNo, rowID);
         			dataDetail.setValue('storageName', simpleRow.storageName, rowID);
         			dataDetail.setValue('floorNo', simpleRow.floorNo, rowID);
         			 
		       		dataDetail.setValue('factoryID', simpleRow.factoryID, rowID);
		       		dataDetail.setValue('factoryNo', simpleRow.factoryName, rowID);
		       		dataDetail.setValue('factoryName', simpleRow.factoryName, rowID);
		       		
					dataDetail.setValue('sbomID', simpleRow.sbomID, rowID);
					dataDetail.setValue('lv', simpleRow.lv, rowID);
					dataDetail.setValue('sttts', simpleRow.sttts, rowID);
					dataDetail.setValue('checkin', simpleRow.checkin, rowID);
//					dataDetail.setValue('costingAmountPer', simpleRow.costingAmountPer, rowID);
//					dataDetail.setValue('costingAmount', simpleRow.costingAmount, rowID);

					//折扣率
					dataDetail.setValue('discountRate', simpleRow.discountRate, rowID);

		    		//设置数量
		       		dataDetail.setValue('itemAmount', simpleRow.priceAmount-simpleRow.invoiceQuantityIng-simpleRow.invoiceQuantity, rowID);
		       		//开票单价
//		       		var itemPrice = common.accDiv(simpleRow.orderAmount,simpleRow.priceAmount);
//		       		dataDetail.setValue('itemPrice', itemPrice, rowID);
		       		dataDetail.setValue('itemPrice', simpleRow.itemPrice, rowID);
		       		//交易单价
		       		dataDetail.setValue('dealPrice', simpleRow.itemPrice, rowID);
		       		
		    	}
	        	
	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		}
		
		
		
		/////////////////////////////////////////////////////////////////////
		Model.triggerConfirmClick = function(event){
			//提交之前
			var options = new Object();
			options.bizData = Model.dataMaster;
			if(systemService.ysyfConfirmBefore(options)==false){
				return;
			}
			// 提交单据
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/confirm';
			systemService.operateBill(data);
		};
		Model.triggerActiveClick = function(event){
			// 撤销提交
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/active';
			systemService.operateBill(data);
		};
		
		Model.triggerAgreeItClick = function(event){
			// 审核单据
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/agreeIt';
			systemService.operateBill(data);
		};
		Model.triggerUnAgreeClick = function(event){
			// 撤销审核
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/unAgree';
			systemService.operateBill(data);
		};
		
		Model.triggerCloseClick = function(event){
			// 关闭单据
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/close';
			systemService.operateBill(data);
		};
		Model.triggerOpenClick = function(event){
			// 撤销审核
			var data = new Object();
			data.bizData = Model.dataMaster;
			data.url = $rootScope.getServiceName() + '/invoice/payableCGFP/single/open';
			systemService.operateBill(data);
		};

		///////////////////////////////////////////////////////////////////////////////
		
		
		//双击事件
		Model.gridListRowDblclick = function(rowIndex,rowID){
			$scope.tabpanel = 'single';
		}
		

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//		Model.objects = {"dataMaster" : Model.dataMaster,"dataDetail" : Model.dataDetail};
		
		var options = {};
		options.container = Model;
		options.concept = 'AccountInvoice';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/invoice/payableCGFP/single/create';
		options.reader = '/invoice/payableCGFP/single/query';
		options.writer = '/invoice/payableCGFP/single/save';
		options.deleter = '/invoice/payableCGFP/single/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},orderType:{name:"orderType",type:"String",label:""},orderTypeLabel:{name:"orderTypeLabel",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},audit:{name:"audit",type:"String",label:""},flowType:{name:"flowType",type:"Integer",label:""},revOpay:{name:"revOpay",type:"String",label:""},direction:{name:"direction",type:"Integer",label:""},confirmDate:{name:"confirmDate",type:"Date",label:""},origin:{name:"origin",type:"String",label:""},originName:{name:"originName",type:"String",label:""},originNo:{name:"originNo",type:"String",label:""},periodStatus:{name:"periodStatus",type:"String",label:""},periodNo:{name:"periodNo",type:"String",label:""},accountInvoiceNo:{name:"accountInvoiceNo",type:"String",label:""},invoiceCategory:{name:"invoiceCategory",type:"String",label:""},invoiceCategoryLabel:{name:"invoiceCategoryLabel",type:"String",label:""},invoiceCode:{name:"invoiceCode",type:"String",label:""},invoiceDate:{name:"invoiceDate",type:"Date",label:""},dealObject:{name:"dealObject",type:"String",label:""},dealObjectLabel:{name:"dealObjectLabel",type:"String",label:""},customerID:{name:"customerID",type:"String",label:""},customerNo:{name:"customerNo",type:"String",label:""},shortName:{name:"shortName",type:"String",label:""},customerName:{name:"customerName",type:"String",label:""},taxType:{name:"taxType",type:"Integer",label:""},taxTypeLabel:{name:"taxTypeLabel",type:"String",label:""},taxRate:{name:"taxRate",type:"Decimal",label:""},fPhone:{name:"fPhone",type:"String",label:""},taxNo:{name:"taxNo",type:"String",label:""},accountBank:{name:"accountBank",type:"String",label:""},accountNo:{name:"accountNo",type:"String",label:""},captionID:{name:"captionID",type:"String",label:""},captionNo:{name:"captionNo",type:"String",label:""},captionName:{name:"captionName",type:"String",label:""},captionFullName:{name:"captionFullName",type:"String",label:""},itemAmount:{name:"itemAmount",type:"Decimal",label:""},orderAmount:{name:"orderAmount",type:"Decimal",label:""},orderAmountOld:{name:"orderAmountOld",type:"Decimal",label:""},orderAmountTax:{name:"orderAmountTax",type:"Decimal",label:""},orderAmountTotal:{name:"orderAmountTotal",type:"Decimal",label:""},orderAmountCleared:{name:"orderAmountCleared",type:"Decimal",label:""},pendingAmount:{name:"pendingAmount",type:"Decimal",label:""},isMember:{name:"isMember",type:"Integer",label:""},memberNo:{name:"memberNo",type:"String",label:""},isHaveCoupon:{name:"isHaveCoupon",type:"Integer",label:""},discountCash:{name:"discountCash",type:"Decimal",label:""},depositRate:{name:"depositRate",type:"Decimal",label:""},accountAmountOld:{name:"accountAmountOld",type:"Decimal",label:""},accountAmountTax:{name:"accountAmountTax",type:"Decimal",label:""},accountAmountTotal:{name:"accountAmountTotal",type:"Decimal",label:""},discountRate:{name:"discountRate",type:"Decimal",label:""},fMasterID:{name:"fMasterID",type:"String",label:""},paymentTerm:{name:"paymentTerm",type:"String",label:""},paymentTermLabel:{name:"paymentTermLabel",type:"String",label:""},predictStart:{name:"predictStart",type:"Date",label:""},predictEnd:{name:"predictEnd",type:"Date",label:""},cashSettle:{name:"cashSettle",type:"Integer",label:""},next:{name:"next",type:"String",label:""},nextName:{name:"nextName",type:"String",label:""},nextNo:{name:"nextNo",type:"String",label:""},settleCategory:{name:"settleCategory",type:"String",label:""},settleCategoryLabel:{name:"settleCategoryLabel",type:"String",label:""},orderNo:{name:"orderNo",type:"String",label:""},projectNo:{name:"projectNo",type:"String",label:""},serialNumber:{name:"serialNumber",type:"String",label:""},resultStatus:{name:"resultStatus",type:"String",label:""},handling:{name:"handling",type:"String",label:""},handlingLabel:{name:"handlingLabel",type:"String",label:""},clearDatetime:{name:"clearDatetime",type:"Datetime",label:""},detailsCount:{name:"detailsCount",type:"Integer",label:""},detailsCountState:{name:"detailsCountState",type:"Integer",label:""},maxDetailNo:{name:"maxDetailNo",type:"Integer",label:""},employeeNo:{name:"employeeNo",type:"String",label:""},employeeName:{name:"employeeName",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
		options.master = {"data":"","relation":""};
		options.directDeleteMode = true;
		options.limit = 15;
		options.orderBy = "accountInvoiceNo DESC";

		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataMasterIndexChanged;
		options.onBeforeNew = Model.dataMasterBeforeNew;
		options.onAfterNew = Model.dataMasterAfterNew;
		options.onBeforeDelete = Model.dataMasterBeforeDelete;
		options.onAfterDelete = Model.dataMasterAfterDelete;
		options.onValueChanged = Model.dataMasterValueChanged;
		options.onDataChanged = Model.dataMasterDataChanged;
		options.onBeforeSave = Model.dataMasterBeforeSave;
		options.onAfterSave = Model.dataMasterAfterSave;
		options.onNewCreateParam = Model.dataMasterNewCreateParam;
		
		Model.dataMaster = new BizData(options);
//		Model.objects.dataMaster = Model.dataMaster;
		//监视对象中的所有变动
		Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值

		
		
		var options = {};
		options.container = Model;
		options.concept = 'AccountInvoiceDetail';
		options.name = 'dataDetail';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.reader = '/invoice/payableCGFP/single/queryDetail';
		options.creater = '/invoice/payableCGFP/single/createDetail';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},audit:{name:"audit",type:"String",label:""},revOpay:{name:"revOpay",type:"String",label:""},direction:{name:"direction",type:"Integer",label:""},confirmDate:{name:"confirmDate",type:"Date",label:""},origin:{name:"origin",type:"String",label:""},originName:{name:"originName",type:"String",label:""},originNo:{name:"originNo",type:"String",label:""},originSerialNo:{name:"originSerialNo",type:"String",label:""},periodStatus:{name:"periodStatus",type:"String",label:""},periodNo:{name:"periodNo",type:"String",label:""},serialNo:{name:"serialNo",type:"String",label:""},accountInvoiceNo:{name:"accountInvoiceNo",type:"String",label:""},fMasterID:{name:"fMasterID",type:"String",label:""},captionID:{name:"captionID",type:"String",label:""},captionNo:{name:"captionNo",type:"String",label:""},captionName:{name:"captionName",type:"String",label:""},captionFullName:{name:"captionFullName",type:"String",label:""},dealObject:{name:"dealObject",type:"String",label:""},dealObjectLabel:{name:"dealObjectLabel",type:"String",label:""},customerID:{name:"customerID",type:"String",label:""},customerNo:{name:"customerNo",type:"String",label:""},shortName:{name:"shortName",type:"String",label:""},customerName:{name:"customerName",type:"String",label:""},taxType:{name:"taxType",type:"Integer",label:""},taxTypeLabel:{name:"taxTypeLabel",type:"String",label:""},taxRate:{name:"taxRate",type:"Decimal",label:""},itemID:{name:"itemID",type:"String",label:""},itemNo:{name:"itemNo",type:"String",label:""},itemName:{name:"itemName",type:"String",label:""},itemProperty:{name:"itemProperty",type:"String",label:""},itemDescribe:{name:"itemDescribe",type:"String",label:""},unitCode:{name:"unitCode",type:"String",label:""},unitName:{name:"unitName",type:"String",label:""},factoryID:{name:"factoryID",type:"String",label:""},factoryNo:{name:"factoryNo",type:"String",label:""},factoryName:{name:"factoryName",type:"String",label:""},storageType:{name:"storageType",type:"String",label:""},storageTypeLabel:{name:"storageTypeLabel",type:"String",label:""},storageID:{name:"storageID",type:"String",label:""},storageNo:{name:"storageNo",type:"String",label:""},storageName:{name:"storageName",type:"String",label:""},floorNo:{name:"floorNo",type:"String",label:""},sbomID:{name:"sbomID",type:"String",label:""},lv:{name:"lv",type:"Integer",label:""},sttts:{name:"sttts",type:"Integer",label:""},checkin:{name:"checkin",type:"Integer",label:""},costingAmount:{name:"costingAmount",type:"Decimal",label:""},costingAmountPer:{name:"costingAmountPer",type:"Decimal",label:""},predictStart:{name:"predictStart",type:"Date",label:""},predictEnd:{name:"predictEnd",type:"Date",label:""},fPhone:{name:"fPhone",type:"String",label:""},itemPrice:{name:"itemPrice",type:"Decimal",label:""},discountRate:{name:"discountRate",type:"Decimal",label:""},discountAmount:{name:"discountAmount",type:"Decimal",label:""},itemAmount:{name:"itemAmount",type:"Decimal",label:""},orderAmount:{name:"orderAmount",type:"Decimal",label:""},orderAmountOld:{name:"orderAmountOld",type:"Decimal",label:""},orderAmountTax:{name:"orderAmountTax",type:"Decimal",label:""},orderAmountTotal:{name:"orderAmountTotal",type:"Decimal",label:""},billDate:{name:"billDate",type:"Date",label:""},dealPrice:{name:"dealPrice",type:"Decimal",label:""},orderNo:{name:"orderNo",type:"String",label:""},projectNo:{name:"projectNo",type:"String",label:""},evaluateQuantityRinse:{name:"evaluateQuantityRinse",type:"Decimal",label:""},evaluateAmountRinse:{name:"evaluateAmountRinse",type:"Decimal",label:""},resultStatus:{name:"resultStatus",type:"String",label:""},employeeNo:{name:"employeeNo",type:"String",label:""},employeeName:{name:"employeeName",type:"String",label:""},comments:{name:"comments",type:"String",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
		options.master = {"data":"dataMaster","relation":"fMasterID"};
		options.directDeleteMode = false;
		options.orderBy = 'serialNo ASC';
		

		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataDetailIndexChanged;
		options.onBeforeNew = Model.dataDetailBeforeNew;
		options.onAfterNew = Model.dataDetailAfterNew;
		options.onBeforeDelete = Model.dataDetailBeforeDelete;
		options.onAfterDelete = Model.dataDetailAfterDelete;
		options.onValueChanged = Model.dataDetailValueChanged;
		options.onDataChanged = Model.dataDetailDataChanged;
//		options.rowsWatcherFn = Model.rowsWatcherFn;
		
		Model.dataDetail = new BizData(options);
//		Model.objects.dataDetail = Model.dataDetail;
		//监视对象中的所有变动
		Model.dataDetail.deregRows = $scope.$watch('Model.dataDetail.rows',Model.dataDetail.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		$scope.tabpanel = 'list';

		var winParams = $rootScope.winParams;
//		console.log('窗口打开时的参数1',winParams);
		if(winParams!=undefined && winParams!=null && winParams!=''){
			if(winParams.fID){
				Model.dataMaster.id = winParams.fID;
				$scope.tabpanel = 'single';
				Model.dataMaster.refreshData();
			}else if(winParams.billNo){
				//增加过滤器，只显示本人及本公司的数据
				Model.dataMaster.filter = "AccountInvoice.billType='" + billType + "'"
//				+ " AND AccountInvoice.clearType='1'"
				+ " AND AccountInvoice.accountInvoiceNo='" + winParams.billNo + "'"
				;
				$scope.tabpanel = 'single';
				Model.dataMaster.refreshData();
			}else{
				
				//增加过滤器，只显示本人及本公司的数据
				Model.dataMaster.filter = "AccountInvoice.billType='" + billType + "'"
//				+ " AND AccountInvoice.clearType='1'"
				;
				
				Model.dataMaster.refreshData();
			}
		}else{
			
			//增加过滤器，只显示本人及本公司的数据
			Model.dataMaster.filter = "AccountInvoice.billType='" + billType + "'"
//			+ " AND AccountInvoice.clearType='1'"
			;
			
			Model.dataMaster.refreshData();
			
		}
		
		
	    return Model;
	}	
	
